<?php
apf_require_controller('Oa_Attendance_Abstract');
apf_require_class('Bll_Attendance_Audit');
apf_require_class("Bll_Attendance_UserInfo");
class Oa_Attendance_TripPrintController extends Oa_Attendance_AbstractController {

    public function handle_request() {
        $params     = $this->request->get_parameters();
        $user_info  = $this->uinfo;
        $leave_id   = intval($params['id']);
        if(!$leave_id){
            $this->apf->get_response()->redirect('/',false,false);
        }
        $bll   = new Bll_Attendance_Audit();
        $leave = $bll->get_leave_info($leave_id);
        //出差 已批准
        if(!(!empty($leave) && $leave['type'] == '出差' && $leave['status'] == '已批准')){
            $this->apf->get_response()->redirect('/',false,false);
        }
        //本人，以及hr可见
        if($user_info['user_id'] != $leave['user_id'] && $user_info['role_name'] != 'HR'){
            $this->apf->get_response()->redirect('/',false,false);
        }
        //详情
        $leavedetail = $bll->get_trip_detail($leave_id);

        $bllUser = new Bll_Attendance_UserInfo;
        //申请人
        $temp_userinfo = $bllUser->get_user_by_ids($leave['user_id']);
        $user_info = $temp_userinfo[0];
        //审批人
        $temp_userinfo = $bllUser->get_user_by_ids($leave['r_user_id']);
        $r_user_info = $temp_userinfo[0];

        $this->request->set_attribute('user',$user_info);
        $this->request->set_attribute('r_user',$r_user_info);
        $leave['start_time'] = date("Y年m月d日 H:i",strtotime($leave['start_time']));
        $leave['end_time'] = date("Y年m月d日 H:i",strtotime($leave['end_time']));
        $leave['apply_time'] = date("Y年m月d日",strtotime($leave['apply_time']));
        $this->request->set_attribute('leave',$leave);
        foreach($leavedetail as $index => $one){
            $leavedetail[$index]['trip_date'] = date("Y年m月d日 H:i", strtotime($one['trip_date']));
        }
        $this->request->set_attribute('leavedetail',$leavedetail);
        return 'Oa_Attendance_TripPrint';
    }
}
